package com.byx.chatclient.manager;

import com.byx.chatclient.entity.MessagePo;
import com.byx.chatclient.entity.MessagePoDao;
import com.byx.chatclient.entity.UserPo;
import com.byx.chatclient.entity.UserPoDao;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

/**
 * @ClassName UserManager
 * @Description 本地用户表管理器
 * @Author Superb
 * @Date 2021/5/6
 * @Version 1.0
 */
public class UserManager extends BaseBeanManager<UserPo,Long> {

    public UserManager(AbstractDao<UserPo, Long> mDao) {
        super(mDao);
    }

    /**
     * 查询本地数据库中登录过的账号
     * @return 用户账号信息
     */
    public List<UserPo> queryLoggedInAccount(){
        QueryBuilder<UserPo> userPoQueryBuilder = queryBuilder();
        //密码非空则判定为此账号登录过
        userPoQueryBuilder.where(UserPoDao.Properties.Password.isNotNull());
        return userPoQueryBuilder.list();
    }

    /**
     * 根据用户登录账号查询用户信息
     * @param loginId
     * @return
     */
    public UserPo queryUserPoByLoginId(String loginId){
        return queryBuilder().where(UserPoDao.Properties.LoginId.eq(loginId)).unique();
    }

    public void deleteByLoginId(String loginId){
        queryBuilder().where(UserPoDao.Properties.LoginId.eq(loginId)).buildDelete().executeDeleteWithoutDetachingEntities();
    }
}
